<template>
  <div class="rank">
    <m-header class="header">
      <div slot="left" @click="$router.push('/discovery')">
        <i class="iconfont icon-xiangzuo" />
      </div>
      <div slot="middle">排行榜</div>
    </m-header>
    <div class="inner">
      <span class="rank__title">官方榜</span>
      <ul class="rank__officialRank" @click="toRankDetail">
        <li v-for="(rank, index) of officialRank" :key="index" :data-id="rank.id">
          <card :image='rank.coverImgUrl' direction='row'>
            <div class="content" slot="leftContent">
              <span class="tracks" v-for="(track,index) of rank.tracks" :key="index">
                {{ index + 1 }} {{ track.first }} - {{ track.second }}
              </span>
            </div>
            <div slot="bottom" class="bottom-txt">
              {{ rank.updateFrequency }}
            </div>
          </card>
        </li>
      </ul>

      <span class="rank__title">更多榜单</span>
      <ul class="rank__otherRank clearfix" @click="toRankDetail">
        <li v-for="(rank, index) of otherRank" :key="index" :data-id='rank.id'>
          <card :image='rank.coverImgUrl' :title="rank.name">
            <div slot="bottom" class="bottom-txt">
              {{ rank.updateFrequency }}
            </div>
          </card>
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
import Card from 'base/card'
import { detail } from 'api/toplist'
import MHeader from 'base/m-header'

export default {
  components: {
    Card,
    MHeader
  },
  data() {
    return {
      officialRank: [],
      otherRank: []
    }
  },
  mounted() {
    this.getSongrank()
  },
  methods: {
    getSongrank() {
      detail().then(res => {
        this.officialRank = res.list.splice(0, 4)
        this.otherRank = res.list
      })
    },
    toRankDetail(e) {
      let node = e.path.find(item => item.nodeName === 'LI' && item.dataset.id)

      if (!node) return

      this.$router.push({
        name: 'playlist',
        params: {
          id: node.dataset.id
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
@import '~@/style/mixins.less';
@import '~@/style/variable.less';
.rank{
  .route-page();
  overflow: auto;
  .inner{
    padding: 0 5px;
    .rank__title{
      display: block;
      font-size: @font-size-normal;
      font-weight: bold;
      margin: 10px 0;
    }
    .rank__officialRank{
      >li{
        margin-bottom: 5px
      }
    }
    .rank__otherRank{
      >li{
        display: block;
        float: left;
        width: 33%;
        height: 150px;
      }
    }
    .content{
      .ellipsis(1);
      .tracks{
        display: block;
        overflow: hidden;
        padding: 5px 0;
      }
    }
    .bottom-txt{
      padding-left: 5px;
    }
  }
}
</style>
